package com.eastfair.point.listener;

import com.alibaba.fastjson.JSON;
import com.eastfair.cache.repository.CachePlusOps;
import com.eastfair.mq.model.MySimpleMessage;
import com.eastfair.mq.service.BusinessPointService;
import com.eastfair.mq.util.MessageExtUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description: 单个业务类型发送
 */
@Slf4j
@Component
@RocketMQMessageListener(topic = "${rocketmq.consumer.businessPointTopic}", consumerGroup = "${rocketmq.consumer.businessPointTopicConsumer}",
        messageModel = MessageModel.CLUSTERING, consumeMode = ConsumeMode.ORDERLY)
public class BusinessPointListner implements RocketMQListener<MySimpleMessage> {

//    @Autowired
//    private BusinessPointService businessPointService;
    @Autowired
    private MessageExtUtil messageExtUtil;

    @Override
    public void onMessage(MySimpleMessage message) {
        if (message==null) {
            return;
        }
//        //消息是否已经消费
//        if (messageExtUtil.isUseMessage(message)) {
//            return;
//        }
//
//        log.info("单个业务类型发送："+JSON.toJSONString(message));
//        //记录日志：顺序写随机读 单向发送
//        businessPointService.execute(message);
//        //清空缓存key
//        messageExtUtil.removeKey(message);
//        businessPointService.execute(message);


    }

}
